package cn.zs.groupmarket.types.design.framework.tree;

import lombok.Getter;
import lombok.Setter;

/**
 * @Description:
 * @Auther: zs
 * @Date: 2024/12/21/11:06
 */

public abstract class AbstractStrategyRouter<T,D,R> implements StrategyMapper<T,D,R>,StrategyHandle<T,D,R>{
    @Setter
    @Getter
    StrategyHandle<T,D,R> defaultHandle = StrategyHandle.DEFAULT ;

    public R router(T requestParameter,D dynamicContext) throws Exception {
        StrategyHandle<T,D,R> handle = get(requestParameter,dynamicContext);
        if (handle == null) {
            return defaultHandle.apply(requestParameter,dynamicContext);
        }
        return handle.apply(requestParameter,dynamicContext);
    }


}


